/*
 * @(#)AbstractVertex.java
 *
 * Revision:
 * Author                                         Date           
 * --------------------------------------------   ------------   
 *  Jeremias D. Serafim de Araujo                     03/02/2012    
 */
package br.edu.ufcg.splab.core.vertex;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import br.edu.ufcg.splab.core.InterfaceEdge;
import br.edu.ufcg.splab.core.InterfaceVertex;




/**
 * 
 * This class represents a graph's vertex. This vertex is 
 * a element of a Graph. @see Graph A vertex is comprised 
 * of one label. It is allowed to have vertex with the same 
 * label, but each one has a different id (UUID).
 * 
 *
 **/

public abstract class AbstractVertex implements InterfaceVertex{

	/**
	 * The vertex's label.
	 */
	private String label;
	/**
	 * The list of the incoming edges for the specified vertex
	 */
	private List<InterfaceEdge> inTransitions;
	/** 
	 * The list of the outgoing edges for the specified vertex
	 */
	private List<InterfaceEdge> outTransitions;
	/**
	 * The id
	 * Is unique for each edge
	 */
	private UUID uuid;
	
	
	/**
	 * Constructor
	 * Create a vertex with the specified label.
	 * 
	 * @param label Vertex's label.
	 */
	public AbstractVertex(String label){
		this.label=label;
		this.inTransitions = new ArrayList<InterfaceEdge>();
		this.outTransitions = new ArrayList<InterfaceEdge>();
		this.uuid = UUID.randomUUID();
	}

	
	
	/**
	 * 
	 * Adds an edge in list of incoming Edges(inTransitions).
	 * @param edge The edge to be added to inTransitions list
	 */
	
	public void addEdgeInTransitions(InterfaceEdge edge){
		this.inTransitions.add(edge);
	}
	
	/**
	 * 
	 * Add an edge to the list of outgoing Edges (outTransitions)
	 * @param edge The edge to be added to outTransitions list
	 */
	public void addEdgeOutTransitions(InterfaceEdge edge){
		this.outTransitions.add(edge);
	}
	
	/**
	 * 
	 * Return true if the vertex is a leaf or false otherwise.
	 * @return  <code>true</code> if the vertex is 
	 * a leaf; <code>false</code> otherwise
	 */
	public boolean isLeaf(){
		return getOutTransitions().size() == 0;
	}
	
	
	/*
	 * 
	 * Gets and Sets.
	 * 
	 */
	
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public List<InterfaceEdge> getInTransitions() {
		return inTransitions;
	}
	public List<InterfaceEdge> getOutTransitions() {
		return outTransitions;
	}
	public UUID getUUID(){
		return this.uuid;
	}
	
	public String toString(){
		return this.label;
	}
	
	public abstract boolean equals(Object o);
	
	
}
